package nku.csc364;

/**
 * 
 * Raj Akula
 * CSC 365 Assignment 5
 * 
 * This Abstract class implements common methods that are used by the two different
 * HashTables. These methods are used in binary concatination and prime number calculation.
 * 
 *
 */


public abstract class AbstractHashTable {

	protected Object[] array;

	public AbstractHashTable(int size, double loadFactor) {
		
		int arraySize = getNextPrime((int) (size / loadFactor));
		array = new Object[arraySize];
	
	}

	public abstract void insert (String key, Object data);
	
	public abstract void delete (String key);
	
	public abstract Object find (String key);
	
	
	
	protected int binaryConcat(String key) {

		int catResult = 0;
		char[] chararray = new char[key.length()];
		key.getChars(0, key.length(), chararray, 0);		

		for (int i = 0; i < chararray.length; i++) {
			catResult = catResult + chararray[i]
					* (32 ^ (chararray.length - i));
		}

		return catResult;

	}

	
	protected int getNextPrime(int val) {

		val++;
	
		while (!isPrime(val)) {
			val++;
		}

		return val;

	}

	private boolean isPrime(int num) {
		boolean retVal = true;

		for (int i = 2; i < num; i++) {
			if ((num % i) == 0) {
				retVal = false;
				break;
			}
		}
		
		
		return retVal;

	}

	
}
